package com.wq.babysecretary.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.wq.babysecretary.R;
import com.wq.babysecretary.base.BaseRxActivity;
import com.wq.babysecretary.model.BaBayMusicModel;
import com.wq.babysecretary.model.BaBayStoryModel;
import com.wq.babysecretary.presenter.BaByMusicPresenter;
import com.wq.babysecretary.presenter.BaByStoryPresenter;
import com.wq.babysecretary.presenter.contract.BabyMusicContract;
import com.wq.babysecretary.presenter.contract.BabyStoryContract;
import com.wq.babysecretary.ui.adapter.BaBayMusicAdapter;
import com.wq.babysecretary.ui.adapter.BaBayStoryAdapter;
import com.wq.babysecretary.weight.itemdecoration.DefaultItemDecoration;
import com.wq.babysecretary.weight.refresh.RefreshLayout;

import java.util.List;

/**
 * Created by qi.wang on 2017/8/24.
 */

public class BaByMusicActivity extends BaseRxActivity<BabyMusicContract.Presenter>implements BabyMusicContract.View{
    RefreshLayout mRlRefresh;
    RecyclerView refresh_rv_content;
    private BaBayMusicAdapter baBayStoryAdapter;
    private Context mContext;
    String url="http://songsearch.kugou.com/song_search_v2?callback=jQuery191034642999175022426_1489023388639&keyword=儿歌&page=1&pagesize=30&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_=1489023388641";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseSetContentView(R.layout.activity_babystory);
        hiddenFooter();
        showGoBackBtn();
        setTitleText("萌宝儿歌");
        mContext=this;
        initView();
    }
    public void initView(){
        mRlRefresh=(RefreshLayout)findViewById(R.id.refresh_layout);
        refresh_rv_content=(RecyclerView) findViewById(R.id.refresh_rv_content);
        mRlRefresh.showLoading();
        mPresenter.refreshBookBrief(url);
        setUpAdapter();
    }
    @Override
    protected void processLogic() {
        super.processLogic();

    }
    private void setUpAdapter(){
        baBayStoryAdapter = new BaBayMusicAdapter();
        refresh_rv_content.setLayoutManager(new LinearLayoutManager(mContext));
        refresh_rv_content.addItemDecoration(new DefaultItemDecoration(mContext));
        refresh_rv_content.setAdapter(baBayStoryAdapter);
    }
    @Override
    public void showError() {
        mRlRefresh.showError();
    }

    @Override
    public void complete() {
        mRlRefresh.showFinish();
    }
    @Override
    public void finishRefreshs(List<BaBayMusicModel> beans) {
        if(beans!=null) {
            if (beans.isEmpty()) {
                mRlRefresh.showEmpty();
                return;
            }
            baBayStoryAdapter.refreshItems(beans);
        }else{
            mRlRefresh.showEmpty();
            return;
        }
    }

    @Override
    protected BabyMusicContract.Presenter bindPresenter() {
        return new BaByMusicPresenter();
    }
}
